<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<jsp:directive.page import="java.sql.PreparedStatement"/>
<jsp:directive.page import="Connectivity.ConnectionManager"/>
<jsp:directive.page import="java.sql.Connection"/>
<jsp:directive.page import="Connectivity.Logger"/>
<jsp:directive.page import="java.sql.CallableStatement"/>
<jsp:directive.page import="java.sql.ResultSet"/>
<jsp:directive.page import="java.sql.Types"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'temp.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
   
<% try{
           Connection con=ConnectionManager.getConnection();
			String assigndetails="";
			String ParameterNames = "";
			int tokcnt=0;
			for(Enumeration e = request.getParameterNames(); e.hasMoreElements(); )
			{
				ParameterNames = (String)e.nextElement();
				//out.println(ParameterNames + "=<br/>");
				String value=request.getParameter(ParameterNames);
				 if(value.equalsIgnoreCase("0") || value.equalsIgnoreCase("Assign")|| value.equalsIgnoreCase("OPEN") || value.equalsIgnoreCase("PFP") || value.equalsIgnoreCase("MTAKEN"))
				 {}
				 else
				{tokcnt++;
				assigndetails=assigndetails+"$"+request.getParameter(ParameterNames);
				
				StringTokenizer st=new StringTokenizer((request.getParameter(ParameterNames)),"#"); 
				//int callentry_id=Integer.parseInt(""+(st.nextToken("1")));
				//int emp_id=Integer.parseInt(""+(st.nextToken("2")));
				while(st.hasMoreTokens())
				{
				String complaint_id=st.nextToken();
				String customer_id=st.nextToken();
     			String emp_eid=st.nextToken();
     			 String created_by=""+(session.getAttribute("uname"));
     			
     			 out.println("created_by:"+created_by);
				 
				out.println("complaint_id:"+complaint_id);
									out.println("customer_id+"+customer_id);
												out.println("emp_id:"+emp_eid);
		CallableStatement cs = null;			
		ResultSet rs = null;
		
		
		out.println("call assigning isgoing---------------------------------------------------------------");
		cs = con.prepareCall("{? = call fun_incall_assign(?,?,?,?)}");
		     cs.registerOutParameter(1,Types.INTEGER);
			 cs.setString(2,complaint_id);
			 cs.setInt(3,Integer.parseInt(customer_id));
			 cs.setInt(4,Integer.parseInt(emp_eid));
			 cs.setString(5,created_by);

			cs.execute();
			
			
			out.println("call signed time to check the result");
			int result =(cs.getInt(1));
			out.println("result:"+result);
			if(result>0)
			{response.sendRedirect("/Genius/form/general/CallAssign.jsp?status=I");}
				//String updateq="UPDATE callentry set call_status='ASSIGNED' where complaint_id="+complaint_id+"	and customer_id="+customer_id+" and status='V'";	
				//PreparedStatement uprs=con.prepareStatement(updateq);
				//boolean k=uprs.execute();
				 //HttpSession session = request.getSession(true);
			   
				//String inassign="INSERT INTO call_assigned(callentry_id,employee_id,created_by)";
				//inassign=inassign+"values (?,?,?)";
				//PreparedStatement inasspr=con.prepareStatement(inassign);
				//inasspr.setInt(1,Integer.parseInt(callentry_id));
				//inasspr.setInt(2,Integer.parseInt(emp_id));
			//	inasspr.setString(3,created_by);
				//boolean s=inasspr.execute();
               	}
               }
//		out.println(problem + "<br/>");
	}
			
	if (tokcnt>0)			 
	{ out.println("----"+tokcnt);//response.sendRedirect("/Genius/form/general/CallAssign.jsp?status=I");
	}
	else
	{out.println("ERROR");}
   }
	
			catch (Exception e)
			{
				
				e.printStackTrace();
				Logger.log("asdfg"+e); }
%>
 
  
  </body>
</html>
